//
//  WJ_Publish_VC.m
//  WJBSApp
//
//  Created by dllo on 16/7/14.
//  Copyright © 2016年 王景伟. All rights reserved.
//
// 这个页面没有夜间模式 需要判断
#import "WJ_Publish_VC.h"
#import "WJPublishTextVC.h"
#import "WJPublishLinksVC.h"
#import "WJPublishPicVC.h"
#import "WJPublishAudioVC.h"
#import "WJPublishVideoVC.h"

@interface WJ_Publish_VC ()

@property (nonatomic,retain) UIImageView *belowImage;

@property (nonatomic,retain) WJBaseButton *cancleButton;

@property (nonatomic,retain) WJBaseView *firView;
@property (nonatomic,retain) WJBaseView *secView;
@property (nonatomic,retain) WJBaseView *thiView;
@property (nonatomic,retain) WJBaseView *forView;
@property (nonatomic,retain) WJBaseView *fifView;
@property (nonatomic,retain) WJBaseView *sixView;


@end

@implementation WJ_Publish_VC

- (void)dealloc
{

    
    // 销毁观察者
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = SECBLACKCOLOR;
    
    // 夜间模式
    [self createView];
    
    // 创建动画效果
    [self createAnimate];
    
    // 创建取消按钮
    [self createCancleButton];

}

- (void)createView
{
    // 创建底部视图
    self.belowImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:self.belowImage];
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Mode"] isEqualToString:@"night"]) {
        
    }else{
        self.belowImage.image = [UIImage imageNamed:@"shareBottomBackground"];
    }
    // 创建观察者
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"changeColor" object:nil];
    
    UIImageView *imageView= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, WIDTH / 6 * 5, 40)];
    imageView.image = [UIImage imageNamed:@"app_sloganN~iphone.png"];
    imageView.center = CGPointMake(WIDTH / 2, HEIGHT / 7);
    [self.view addSubview:imageView];
    
 }


- (void)createAnimate
{
    // 创建 6个图片
    self.firView = [[WJBaseView alloc]initWithFrame:CGRectMake(WIDTH / 18, 0, WIDTH * 2 / 9, WIDTH * 5 / 18) imageName:@"publish-video.png" name:@"发视屏"];
    [self.view addSubview:_firView];
    
     self.secView = [[WJBaseView alloc]initWithFrame:CGRectMake(WIDTH * 7 / 18, 0, WIDTH * 2 / 9, WIDTH * 5 / 18) imageName:@"publish-picture.png" name:@"发图片"];
    [self.view addSubview:_secView];
    
     self.thiView = [[WJBaseView alloc]initWithFrame:CGRectMake(WIDTH * 13 / 18, 0, WIDTH * 2 / 9, WIDTH * 5 / 18) imageName:@"publish-text.png" name:@"发段子"];
    [self.view addSubview:_thiView];
    
     self.forView = [[WJBaseView alloc]initWithFrame:CGRectMake(WIDTH / 18, 0, WIDTH * 2 / 9, WIDTH * 5 / 18) imageName:@"publish-audio.png" name:@"发声音"];
    [self.view addSubview:_forView];
    
     self.fifView = [[WJBaseView alloc]initWithFrame:CGRectMake(WIDTH * 7/ 18, 0, WIDTH * 2 / 9, WIDTH * 5 / 18) imageName:@"publish-review.png" name:@"看神贴"];
    [self.view addSubview:_fifView];
    
     self.sixView = [[WJBaseView alloc]initWithFrame:CGRectMake(WIDTH  * 13/ 18, 0, WIDTH * 2 / 9, WIDTH * 5 / 18) imageName:@"publish-link~iphone.png" name:@"发链接"];
    [self.view addSubview:_sixView];
    
    
#pragma mark - 添加手势
    UITapGestureRecognizer *firtap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(firAction:)];
    [self.firView addGestureRecognizer:firtap];
    UITapGestureRecognizer *sectap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(secAction:)];
    [self.secView addGestureRecognizer:sectap];
    UITapGestureRecognizer *thitap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(thiAction:)];
    [self.thiView addGestureRecognizer:thitap];
    UITapGestureRecognizer *fortap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(forAction:)];
    [self.forView addGestureRecognizer:fortap];
    UITapGestureRecognizer *fiftap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(fifAction:)];
    [self.fifView addGestureRecognizer:fiftap];
    UITapGestureRecognizer *sixtap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sixAction:)];
    [self.sixView addGestureRecognizer:sixtap];

}

- (void)viewWillAppear:(BOOL)animated
{
    [UIView animateWithDuration:0.4 animations:^{
        
        self.firView.frame = CGRectMake(WIDTH / 18, HEIGHT / 2 - WIDTH / 3, WIDTH * 2 / 9, WIDTH * 5 / 18) ;
        self.thiView.frame = CGRectMake(WIDTH * 13 / 18, HEIGHT / 2 - WIDTH / 3, WIDTH * 2 / 9, WIDTH * 5 / 18);
        self.forView.frame = CGRectMake(WIDTH / 18, HEIGHT / 2 + WIDTH / 18, WIDTH * 2 / 9, WIDTH * 5 / 18);
        self.fifView.frame = CGRectMake(WIDTH * 7/ 18, HEIGHT / 2 + WIDTH / 18, WIDTH * 2 / 9, WIDTH * 5 / 18);
        self.sixView.frame = CGRectMake(WIDTH  * 13/ 18, HEIGHT / 2 + WIDTH / 18, WIDTH * 2 / 9, WIDTH * 5 / 18);
        
    } completion:nil];
    
    
    [UIView animateWithDuration:0.5 animations:^{
        self.secView.frame = CGRectMake(WIDTH * 7 / 18, HEIGHT / 2 - WIDTH / 3, WIDTH * 2 / 9, WIDTH * 5 / 18);
    } completion:nil];
    
}

- (void)createCancleButton
{
    self.cancleButton = [WJBaseButton buttonWithType:UIButtonTypeCustom];
    self.cancleButton.frame = CGRectMake(0, HEIGHT - 49, WIDTH, 49);
    [self.view addSubview:_cancleButton];
    [_cancleButton setImage:[UIImage imageNamed:@"shareButtonCancel"] forState:UIControlStateNormal];
    [_cancleButton setImage:[UIImage imageNamed:@"shareButtonCancelClick"] forState:UIControlStateHighlighted];
    [_cancleButton addTarget:self action:@selector(cancle) forControlEvents:1<<6];
}

- (void)cancle
{
   
    
    // 结束动画
    [UIView animateWithDuration:0.2 animations:^{
        self.firView.frame = CGRectMake(WIDTH / 18, HEIGHT / 2 - WIDTH / 3 - WIDTH / 18, WIDTH * 2 / 9, WIDTH * 5 / 18) ;
        self.thiView.frame = CGRectMake(WIDTH * 13 / 18, HEIGHT / 2 - WIDTH / 3 - WIDTH / 18, WIDTH * 2 / 9, WIDTH * 5 / 18);
        self.forView.frame = CGRectMake(WIDTH / 18, HEIGHT / 2 + WIDTH / 18- WIDTH / 18, WIDTH * 2 / 9, WIDTH * 5 / 18);
        self.fifView.frame = CGRectMake(WIDTH * 7/ 18, HEIGHT / 2 + WIDTH / 18- WIDTH / 18, WIDTH * 2 / 9, WIDTH * 5 / 18);
        self.sixView.frame = CGRectMake(WIDTH  * 13/ 18, HEIGHT / 2 + WIDTH / 18- WIDTH / 18, WIDTH * 2 / 9, WIDTH * 5 / 18);

    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 animations:^{
            self.firView.frame = CGRectMake(WIDTH / 18, HEIGHT , WIDTH * 2 / 9, WIDTH * 5 / 18) ;
            self.thiView.frame = CGRectMake(WIDTH * 13 / 18, HEIGHT , WIDTH * 2 / 9, WIDTH * 5 / 18);
            self.forView.frame = CGRectMake(WIDTH / 18, HEIGHT , WIDTH * 2 / 9, WIDTH * 5 / 18);
            self.fifView.frame = CGRectMake(WIDTH * 7/ 18, HEIGHT , WIDTH * 2 / 9, WIDTH * 5 / 18);
            self.sixView.frame = CGRectMake(WIDTH  * 13/ 18, HEIGHT , WIDTH * 2 / 9, WIDTH * 5 / 18);
   
        } completion:^(BOOL finished) {
            
             [self dismissViewControllerAnimated:YES completion:nil];
        }];
    }];
    
    // 第二个的结束动画
    [UIView animateWithDuration:0.25 animations:^{
        
        self.secView.frame = CGRectMake(WIDTH * 7 / 18, HEIGHT / 2 - WIDTH / 3- WIDTH / 18, WIDTH * 2 / 9, WIDTH * 5 / 18);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3 animations:^{
            self.secView.frame = CGRectMake(WIDTH * 7 / 18, HEIGHT , WIDTH * 2 / 9, WIDTH * 5 / 18) ;
            
        } completion:^(BOOL finished) {
            
            [self dismissViewControllerAnimated:YES completion:nil];
        }];
    }];
}

-(void)firAction:(UITapGestureRecognizer *)tap{
    NSLog(@"发视屏");
    WJPublishVideoVC *Links = [[WJPublishVideoVC alloc]init];
    [self presentViewController:Links animated:YES completion:nil];
}

-(void)secAction:(UITapGestureRecognizer *)tap{
    NSLog(@"发图片");
    WJPublishPicVC *Pic = [[WJPublishPicVC alloc]init];
    [self presentViewController:Pic animated:YES completion:nil];
}

-(void)thiAction:(UITapGestureRecognizer *)tap{
    NSLog(@"发段子");
    WJPublishTextVC *publish = [[WJPublishTextVC alloc]init];
    [self presentViewController:publish animated:YES completion:nil];
}

-(void)forAction:(UITapGestureRecognizer *)tap{
    NSLog(@"发声音");
    WJPublishAudioVC *Links = [[WJPublishAudioVC alloc]init];
    [self presentViewController:Links animated:YES completion:nil];
}

-(void)fifAction:(UITapGestureRecognizer *)tap{
    NSLog(@"发神贴");
    [self cancle];
}

-(void)sixAction:(UITapGestureRecognizer *)tap{
    NSLog(@"发链接");
    WJPublishLinksVC *Links = [[WJPublishLinksVC alloc]init];
    [self presentViewController:Links animated:YES completion:nil];
}






























































- (void)changeColor:(NSNotification *)cation
{
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"Mode"] isEqualToString:@"night"]) {
        
    }else{
        self.belowImage.image = [UIImage imageNamed:@"shareBottomBackground"];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
